import pygame

class Ship:
    def __init__(self,ai_game) -> None:
        # 获得到游戏界面信息
        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()

        # 获取飞船图片和位置
        self.image = pygame.image.load('images/ship.bmp')
        self.rect = self.image.get_rect()

        self.rect.midbottom = self.screen_rect.midbottom

        # 标记飞船移动的两个变量, True移动、False静止
        self.moving_right = False
        self.moving_left = False

    def center_ship(self):
        '''设置飞船复位'''
        self.rect.midbottom = self.screen_rect.midbottom

    def update(self, speed):
        '''更新飞船位置'''
        # 设置飞船位置，并限制活动区域
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.rect.x += speed
        elif self.moving_left and self.rect.left > 0:
            self.rect.x -= speed
        else:
            pass

    def blitme(self):
        self.screen.blit(self.image, self.rect)
